//package com.colorfruit.admin.control.handler;
//
//import com.colorfruit.admin.pojo.enums.ErrorCodeEnum;
//import com.colorfruit.framework.model.pojo.BaseResult;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.converter.HttpMessageNotReadableException;
//import org.springframework.web.HttpMediaTypeNotSupportedException;
//import org.springframework.web.HttpRequestMethodNotSupportedException;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.bind.annotation.ResponseStatus;
//
///**
// * 业务描述：统一异常处理，使用时继承加注解@Component即可
// *
// * @Auther: chenjiayuan
// * @Date: create in 2018/7/3 09
// * @Description:
// */
//@Slf4j
//@ResponseBody
//@ControllerAdvice
//public class WebExeptionHandler {
//
//    /**
//     * 400 - Bad Request
//     */
//    @ResponseStatus(HttpStatus.BAD_REQUEST)
//    @ExceptionHandler(HttpMessageNotReadableException.class)
//    public BaseResult handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
//        log.error("参数解析失败,400", e);
//        return new BaseResult(ErrorCodeEnum.ACCESS_ERROR.getCode(),"异常：400-Bad request！");
//    }
//
//    /**
//     * 405 - Method Not Allowed
//     */
//    @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
//    @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
//    public BaseResult handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
//        log.error("不支持当前请求方法", e);
//        return new BaseResult(ErrorCodeEnum.ACCESS_ERROR.getCode(),"异常：405 - Method Not Allowed！");
//    }
//
//    /**
//     * 415 - Unsupported Media Type
//     */
//    @ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
//    @ExceptionHandler(HttpMediaTypeNotSupportedException.class)
//    public BaseResult handleHttpMediaTypeNotSupportedException(Exception e) {
//        log.error("不支持当前媒体类型", e);
//        return new BaseResult(ErrorCodeEnum.ACCESS_ERROR.getCode(),"异常：415 - Unsupported Media Type！");
//    }
//
//    /**
//     * 500 - Internal Server Error
//     */
//    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
//    @ExceptionHandler(Exception.class)
//    public BaseResult handleException(Exception e) {
//        if (e instanceof ValidateException){
//            //参数校验异常业务异常
//            log.info("param error:msg:{}======detail:",e.getMessage(),e);
//            return new BaseResult(ErrorCodeEnum.PARAM_ERROR.getCode(),e.getMessage());
//        }
//        log.error("服务运行异常", e);
//        return new BaseResult(ErrorCodeEnum.SYSTEM_ERROR.getCode(), ErrorCodeEnum.SYSTEM_ERROR.getMsg());
//    }
//}
